/**
 * @param {number[]} distance
 * @param {number} start
 * @param {number} destination
 * @return {number}
 */
export var distanceBetweenBusStops = function (distance, start, destination) {
  if (start === destination) return 0
  if (start > destination) [start, destination] = [destination, start]
  let ansI = 0
  let ansJ = 0
  let [i, j] = [start, destination]
  while (i !== destination || j !== start) {
    if (i !== destination) {
      ansI += distance[i]
      i++
    }
    if (j !== start) {
      ansJ += distance[j]
      j = j + 1 === distance.length ? 0 : j + 1
    }
    if (i === destination && ansI <= ansJ) return ansI
    if (j === start && ansJ <= ansI) return ansJ
  }
  console.log(ansI, ansJ)
  return Math.min(ansI, ansJ)
}
